﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;

namespace Puddy
{
    [DataContract()]
    public class GoogleGeocodeAddressResponse
    {
        [DataMember(Name = "status")]
        public string Status { get; set; }

        public static GoogleGeocodeAddressResponse ParseFromJSON(String jsonData)
        {

            GoogleGeocodeAddressResponse output;
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GoogleGeocodeAddressResponse));
            using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(jsonData)))
            {
                output = serializer.ReadObject(stream) as GoogleGeocodeAddressResponse;
            }
            return output;
        }

        [DataMember(Name = "results")]
        public List<result> Results { get; set; }

        [DataContract()]
        public class result
        {
            [DataMember(Name = "address_components")]
            public List<address_component> AddressComponents { get; set; }

            [DataMember(Name = "formatted_address")]
            public string FormattedAddress { get; set; }

            [DataMember(Name = "geometry")]
            public geometry Geometry { get; set; }

            [DataContract()]
            public class geometry
            {
              

                [DataContract()]
                public class bound
                {
                    [DataMember(Name = "northeast")]
                    public bound_area Northeast { get; set; }

                    [DataMember(Name = "southwest")]
                    public bound_area Southwest { get; set; }


                }

                [DataMember(Name = "location")]
                public bound_area Location { get; set; }

                [DataMember(Name = "location_type")]
                public string LocationType { get; set; }

                [DataMember(Name = "viewport")]
                public bound Viewport { get; set; }

                [DataContract()]
                public class bound_area
                {
                    [DataMember(Name = "lat")]
                    public double Latitude { get; set; }

                    [DataMember(Name = "lng")]
                    public double Longtitude { get; set; }
                }
            }

            [DataContract()]
            public class address_component
            {
                [DataMember(Name = "long_name")]
                public string LongName { get; set; }

                [DataMember(Name = "short_name")]
                public string ShortName { get; set; }

                [DataMember(Name = "types")]
                public List<string> Types { get; set; }
            }
        }
    }
}
